﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BackGround_DetailInfo : System.Web.UI.Page
{
    Operation operation = new Operation();
    int id;
    protected void Page_Load(object sender, EventArgs e)

    {
        if (Session["Admin"] == null)
        {
            WebMessageBox.Show("会话失效，请重新登录！");
        }
        else
        {
            Image1.ImageUrl = "im/default.jpg";
        }
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //DataSet ds = operation.getMaxId();  //最后一个ID号命名
        DataSet ds = operation.SelectInfo("新闻信息");
        int name = (int)ds.Tables[0].Rows[0][0]; //用来命名图片


        if (FileUpload1.FileName != "" && FileUpload1 != null)
        {
            string file = FileUpload1.FileName; //得到文件名

            string type = file.Substring(file.LastIndexOf(".") + 1);        //图片格式

            if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp" || type == "png")
            { //判断是否为图片类型


                FileUpload1.PostedFile.SaveAs(Server.MapPath("im/" + name + ".jpg")); //上传图片
                Response.Write("<script>alert('上传成功');</script>");
                Image1.ImageUrl = "im/" + name + ".jpg";
              
            }
            else
            {
                Response.Write("<script>alert('非图片类型，不允许上传！');</script>");

            }
        }
        else
        {
            Response.Write("<script>alert('必须指定文件！');</script>");

        }
        Button3.Visible = true;
        Button1.Visible = false;
        FileUpload1.Visible = false;
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("CheckInfo.aspx?id=新闻信息");
      
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Button1.Visible = true;
        FileUpload1.Visible = true;
        Button3.Visible = false;
    }
}
